package router

import (
	"github.com/gin-gonic/gin"
	"goDemo/entity"
	"strconv"
	"time"
)
import "goDemo/db"

func User(c *gin.Context) {
	pageSize, _ := strconv.Atoi(c.DefaultQuery("pageSize", "10"))
	pageNum, _ := strconv.Atoi(c.DefaultQuery("pageNum", "1"))
	us, total := db.Get(pageNum, pageSize)
	c.JSON(200, gin.H{
		"total": total,
		"data":  us,
	})
}

func Add(c *gin.Context) {
	user := entity.User{Name: c.DefaultQuery("name", "new"),DatachangeLasttime: time.Now()}
	add := db.Add(user)
	c.JSON(200, gin.H{
		"msg": add,
	})
}

func Conn(c *gin.Context) {
	c.JSON(200, gin.H{
		"msg": db.Conn(),
	})
}
